using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using FitnessClub.Bll.StaffManager;

public partial class EmployeesHolidays : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (StateManager.Instance.IsNullInSession(SessionKeys.EmployeeId))
            Response.Redirect("Employees.aspx");
        if (!IsPostBack)
        {
            int employeeId = StateManager.Instance.GetFromSession<int>(SessionKeys.EmployeeId);
            List<ResListEmp> employees = Delegate.getAllEmployee();
            foreach (ResListEmp emp in employees)
            {
                if (emp.Id != employeeId)
                    continue;
                lblImie.Text = emp.Name;
                lblNazwisko.Text = emp.Surname;
            }
            GridView1.DataSource = Delegate.getAllEmployeeHolidays(employeeId);
            GridView1.DataBind();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("Employees.aspx");
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.DataRow)
        {
            return;
        }
        ResListEmpHolidays res = (ResListEmpHolidays)e.Row.DataItem;
        ((Label)e.Row.FindControl("lblOd")).Text = res.From.ToShortDateString();
        ((Label)e.Row.FindControl("lblDo")).Text = res.To.Date.ToShortDateString();
        ((Label)e.Row.FindControl("lblTyp")).Text = res.Type.ToString();
        ((Label)e.Row.FindControl("lblOpis")).Text = res.Description.ToString();
        ((Button)e.Row.FindControl("btnUsun")).CommandName = res.Id.ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("EmployeesHolidaysAdd.aspx");
    }
    protected void btnUsun_Click(object sender, EventArgs e)
    {
        Button but = (Button)sender;
        int id = int.Parse(but.CommandName);
        bool result = Delegate.removeUrlopEmployee(id);
        if (!result)
        {
            lblDeleteError.Visible = true;
        }
        else
            Response.Redirect("EmployeesHolidays.aspx");
    }
}
